package ch.fusun.baron.city;

/**
 * The city model
 */
public class City {
	private int id;
	private int population;

	/**
	 * Kryonet constructor
	 */
	public City() {
		// kryo
	}

	/**
	 * @param id
	 *            The id
	 */
	public City(int id) {
		this.id = id;
		this.population = 1;
	}

	/**
	 * @return The population
	 */
	public int getPopulation() {
		return population;
	}

	/**
	 * @param population
	 *            The population
	 */
	public void setPopulation(int population) {
		this.population = population;
	}

	/**
	 * @param population
	 *            additional population
	 */
	public void increasePopulation(int population) {
		this.population += population;
	}

	/**
	 * @param population
	 *            people who died
	 */
	public void decreasePopulation(int population) {
		increasePopulation(-population);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		City other = (City) obj;
		if (id != other.id)
			return false;
		return true;
	}

	/**
	 * @return is the city dead?
	 */
	public boolean isDead() {
		return population <= 0;
	}
}
